#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <time.h>
#include "main.h"


#include "WorldStatusUpdate.pb.h"
#include "Commands.pb.h"
#include "ProtobufUtil.hh"

using namespace strategy_protocol;
using namespace protoutil;
using namespace std;

void TheStrategy::worker_to_mine(WorldStatusUpdateMessage_Worker worker,Position mine_position)
{
    bool brave=false;
    for(int i=0;the_brave_workers.size();i++)
	if(worker.common().id()==the_brave_workers[i]) brave=true;

	if(!brave)
	{
		if(worker.resource() == 0)
		{
			workers_task[worker.common().id()].target_pos=mine_position;
			workers_task[worker.common().id()].approx=false;
		}
		else
		{
			if(world.bases_size()>0)
			{
				workers_task[worker.common().id()].target_pos=base_pos;
				workers_task[worker.common().id()].approx=true;
			}
		}
	}
}

void TheStrategy::workers_to_mine()
{
	for(int i=0;i<world.workers_size();i++)
	{
		bool mine_exists=false;
		for(int j=0;j<mines.size() && !mine_exists;j++)
			if(same_pos(mines[j].common().position(),his_mine[world.workers(i).common().id()])
					&& mines[j].capacity()>0) mine_exists=true;
		if(!mine_exists)
//        {
//			worker_to_mine(world.workers(i),his_mine[world.workers(i).common().id()]);
//        }
//		else
			what_should_i_do(world.workers(i),false);
	}
    workers_on_the_best_routes();
}
